package cn.ac.iscas.action.login;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.ac.iscas.bean.user.User;
import cn.ac.iscas.service.user.IUserService;

@Controller @Scope("prototype")
public class LoginAction {
	@Resource public IUserService userService; 
	private String userName;
	private String password;
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getUserName() {
		return userName;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getPassword() {
		return password;
	}
	public String login()
	{
		ActionContext.getContext().put("message","");
		return "login";
	}
	public String check()
	{
		User user= userService.checkUser(userName, password);
		
		if(user!=null)
		{
			ActionContext.getContext().getSession().put("user",user);
			ActionContext.getContext().put("message","登陆成功");
		}
		else
		{
			ActionContext.getContext().put("message", "用户名或密码错误");
			return "login";
		}
		return "success";
	}
	public String logout(){
		ActionContext.getContext().getSession().remove("user");
	    ActionContext.getContext().put("message", "成功退出");
		return "login";
	}
}
